<!-- 循环天数 -->

<template>
  <EasyScroll :key="one.scheduleType === 1 ? 0 : one.cycleNum" :height="height" class="ScheduleQueue-ModalCycle">
    <FormSlot
      v-for="(item, i) in one.cycles"
      :key="item.id || item.key"
      :label="one.scheduleType === 1 ? '每一天' : `第 ${i + 1} 天`"
      noMargin
    >
      <div class="flex">
        <QueuePreview :obj="item.time" :extra="one.cycles.at(i - 1).time" hasText class="flex1" />

        <div class="CoreWeb-RowOperate">
          <BtnText v-if="item.scheduleTimeId && !isShow" title="清除" red @click="clearCycle(item)" />
          <BtnText v-if="!item.scheduleTimeId && !isShow" title="选择" @click="openTime(item)" />
        </div>
      </div>
    </FormSlot>
  </EasyScroll>
</template>

<script>
// ============================== 导入依赖 ============================== //

import CORE from '@/CORE'

// ============================== 导出组件 ============================== //

export default {
  /**
   * 名称定义 (实际使用名称)
   */
  name: 'ModalCycle',

  /**
   * 混入列表 (配置选项合并)
   */
  mixins: [CORE.mixWeb(), CORE.mixWeb('time', 'time_')],

  /**
   * 组件导入 (Abc.vue + Abc/index.vue)
   */
  ...CORE.components(require.context('@admin/views/Maintain/Schedule/components', true, /vue$/)),

  /**
   * 计算属性 (慎用箭头函数)
   */
  computed: {
    /**
     * 高度
     */
    height() {
      return this.one.cycles.length > 7 ? 427 : null
    },
  },

  /**
   * 本地方法 (轻量重要在前)
   */
  methods: {
    /**
     * 打开班时弹窗
     */
    openTime(item) {
      this.one.cycle = item
      this.time_openShow()
    },

    /**
     * 清除循环的某天
     */
    clearCycle(item) {
      item.scheduleTimeId = ''
      item.time = CORE.clone(this.INIT_ONE.cycle.time)
    },
  },
}
</script>

<style lang="scss">
@import './index.scss';
</style>
